package com.cifz.reducerdemo

import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.redux.core.StoreSubscriber
import com.redux.core.Subscription

class MainActivity : AppCompatActivity(), StoreSubscriber<AppState> {
    lateinit var tv: TextView

    var str : String
        get() {
           return this.str
        }
        set(value) {
            Log.d("MainActivity",value)
            Toast.makeText(this,value,Toast.LENGTH_SHORT).show()
        }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        tv = findViewById(R.id.tv)
        findViewById<Button>(R.id.btn).setOnClickListener {
            store.dispatch(TestOneAction(content = "嘿嘿"))
        }
    }


    override fun onStart() {
        super.onStart()
        store.subscribe(this) { it ->
            it.select {
                it
            }
        }
    }

    override fun newState(state: AppState) {
        Log.d(Constant.TAG, "UI层收到的消息 : ${state.content}")
    }


}



